
const cf3 = require('../../../utils/config3')
import Config from '../../../utils/config2'
var regeneratorRuntime = require("../../../lib/js/runtime-module.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    houseActivityList:[],
    title:'房源活动',
    currPage:1,
    pageSize:11,
    totalCount:0,
    noData:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.projectId){
      this.getHouseActivityList(options.projectId)
    }
    if(options.projectIds){
       this.data.projectIds= options.projectIds;
       this.getHouseActivityLists();
    }
  },
  //获取多个楼盘活动
  getHouseActivityLists(){
    let { currPage,pageSize,projectIds,houseActivityList,noData } = this.data;
    let param = {
      type:1,projectIds
    };
    let that = this;
    wx.request({
      url: Config.dataCenter+`wxopen/activity/${currPage}/${pageSize}`,
      data:param,
      type: "GET",
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('authName')
      },
      success:function(res){
        if(res.data.code==200){
          
            if (currPage.pageNo > 1) {
              houseActivityList = houseActivityList.concat(res.data.data.list);
             } else {
               if(res.data.data.list.length==0) noData = true;
              houseActivityList = res.data.data.list;
             }

          that.setData({
            houseActivityList,
            totalCount:res.data.data.totalCount,
            noData
          });
        }
       
      }
    })
  },
  // 获取活动房源
  getHouseActivityList:async function(data){
    var that = this
    wx.request({
      // url: `${cf3.config.pageDomain}wecp/wxopenActivitySetting/list?type=1&projectId=${data.outerId}`,
      url: `${cf3.config.pageDomain}wecp/wxopenActivitySetting/list?type=1&projectId=${data}&publishStatus=2&openStatus=1`,
      data:{},
      header: {
        'content-type': 'application/json',
        // 'token':wx.getStorageSync('authName')
      },
      success:function(res){
        console.log(res)
        let {results} = res.data
        if(results.length>0){
          that.setData({
            houseActivityList:results
          });
        }
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    if(this.data.projectIds){
      this.setData({
        currPage: 1
    });
    this.getHouseActivityLists();
    }

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let {totalCount,houseActivityList,currPage,projectIds} =  this.data;
    if(projectIds&&houseActivityList.length<totalCount){
      currPage +=1
      // this.data.currPage = currPage;
      this.setData({
        currPage
      })
      this.getHouseActivityLists()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})